
package com.cn.jinl.utils.msgSend;


import com.alibaba.fastjson.JSONObject;

public class JsonReqClient extends AbsRestClient {

	@Override
	public String sendSms(String sid, String token, String appid, String templateid, String param, String mobile,
			String uid) {

		String result = "";

		try {
			String url = getStringBuffer().append("/sendsms").toString();

			JSONObject jsonObject = new JSONObject();
			jsonObject.put("sid", sid);
			jsonObject.put("token", token);
			jsonObject.put("appid", appid);
			jsonObject.put("templateid", templateid);
			jsonObject.put("param", param);
			jsonObject.put("mobile", mobile);
			jsonObject.put("uid", uid);

			String body = jsonObject.toJSONString();

			System.out.println("body = " + body);

			result = HttpClientUtil.postJson(url, body, null);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public String sendSmsBatch(String sid, String token, String appid, String templateid, String param, String mobile,
			String uid) {

		String result = "";

		try {
			String url = getStringBuffer().append("/sendsms_batch").toString();

			JSONObject jsonObject = new JSONObject();
			jsonObject.put("sid", sid);
			jsonObject.put("token", token);
			jsonObject.put("appid", appid);
			jsonObject.put("templateid", templateid);
			jsonObject.put("param", param);
			jsonObject.put("mobile", mobile);
			jsonObject.put("uid", uid);

			String body = jsonObject.toJSONString();

			System.out.println("body = " + body);

			result = HttpClientUtil.postJson(url, body, null);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public String addSmsTemplate(String sid, String token, String appid, String type, String template_name,
			String autograph, String content) {

		String result = "";

		try {
			String url = getStringBuffer().append("/addsmstemplate").toString();

			JSONObject jsonObject = new JSONObject();
			jsonObject.put("sid", sid);
			jsonObject.put("token", token);
			jsonObject.put("appid", appid);
			jsonObject.put("type", type);
			jsonObject.put("template_name", template_name);
			jsonObject.put("autograph", autograph);
			jsonObject.put("content", content);

			String body = jsonObject.toJSONString();

			System.out.println("body = " + body);

			result = HttpClientUtil.postJson(url, body, null);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public String getSmsTemplate(String sid, String token, String appid, String templateid, String page_num,
			String page_size) {

		String result = "";

		try {
			String url = getStringBuffer().append("/getsmstemplate").toString();

			JSONObject jsonObject = new JSONObject();
			jsonObject.put("sid", sid);
			jsonObject.put("token", token);
			jsonObject.put("appid", appid);
			jsonObject.put("templateid", templateid);
			jsonObject.put("page_num", page_num);
			jsonObject.put("page_size", page_size);

			String body = jsonObject.toJSONString();

			System.out.println("body = " + body);

			result = HttpClientUtil.postJson(url, body, null);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public String editSmsTemplate(String sid, String token, String appid, String templateid, String type,
			String template_name, String autograph, String content) {

		String result = "";

		try {
			String url = getStringBuffer().append("/editsmstemplate").toString();

			JSONObject jsonObject = new JSONObject();
			jsonObject.put("sid", sid);
			jsonObject.put("token", token);
			jsonObject.put("appid", appid);
			jsonObject.put("templateid", templateid);
			jsonObject.put("type", type);
			jsonObject.put("template_name", template_name);
			jsonObject.put("autograph", autograph);
			jsonObject.put("content", content);

			String body = jsonObject.toJSONString();

			System.out.println("body = " + body);

			result = HttpClientUtil.postJson(url, body, null);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public String deleterSmsTemplate(String sid, String token, String appid, String templateid) {

		String result = "";

		try {
			String url = getStringBuffer().append("/deletesmstemplate").toString();

			JSONObject jsonObject = new JSONObject();
			jsonObject.put("sid", sid);
			jsonObject.put("token", token);
			jsonObject.put("appid", appid);
			jsonObject.put("templateid", templateid);

			String body = jsonObject.toJSONString();

			System.out.println("body = " + body);

			result = HttpClientUtil.postJson(url, body, null);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static void main(String args[]){
		String sid = "348fbfcca7b1427da858b294ca3a70b8";
		String token = "fa8f52381b11157c9de582bc21719722";
		String appid = "244805dcd7e84117b57b346c49c42d6b";
		String templateid = "608770";
		String param = "12333,60";
		String mobile = "15950532873";
		String uid = "";
		JsonReqClient jsonReqClient = new JsonReqClient();
		String code = String.valueOf((int) ((Math.random() * 9 + 1) * Math.pow(10,5)));
		System.out.println(code);
		jsonReqClient.sendSms(sid, token, appid, templateid, param, mobile, uid);
	}

}
